package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.UnitDO;
import com.smart.model.request.UnitRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@Repository
public interface UnitMapper extends BaseMapper<UnitDO> {
    UnitDO selectDOById(Long id);
    List<UnitDO> selectDOList(UnitDO unit);
    int insertDO(UnitDO unit);
    int batchInsertDO(List<UnitDO> unitDOList);
    int updateDO(UnitDO unit);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from unit",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") UnitRequest param);
    @Select({"<script>",
            "   select * from unit",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<UnitDO> pageQuery(@Param("param") UnitRequest param, @Param("limit") int limit, @Param("offset") long offset);

    List<UnitDO> selectDOListByReq(UnitRequest request);

    List<Map<String, Object>> selectAllUnitName(@Param("unitType") String unitType,@Param("projectId")Long projectId);

    List<Map<String, Object>> selectAllUnitNameByJsId(@Param("unitType") String unitType,@Param("jiansheUnitId")  Long jiansheUnitId);

    List<UnitDO> selectByProjectId(Long projectId);

}
